<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

$api = app('Dingo\Api\Routing\Router');

$api->version('v1', [
    'namespace' => 'App\Http\Controllers\Api',
    //translate层, 返回的数据格式
    'middleware'=>'serializer:array'
], function ($api) {

    $api->group(['middleware' => 'api.throttle', 'limit' => config('api.rate_limits.sign.limit'), 'expires' => config('api.rate_limits.sign.expires')], function ($api) {
        //图形验证码->短信验证码->用户注册
        $api->post('captchas', 'CaptchasController@store')->name('api.captchas.store');
        $api->post('verifyCodes', 'VerificationCodesController@store')->name('api.verifyCodes.store');
        $api->post('users', "UserController@store")->name('api.users.register');
        //登录授权路径
        $api->post('authorizations', "AuthorizationsController@store")->name('api.authorizations.store');
        $api->post('socials/{social_type}/authorizations', "AuthorizationsController@weiXinLogin")->name('api.socials.authorizations.store');
        $api->put('authorizations', "authorizationsController@refresh")->name('api.authorizations.refresh');
        $api->delete('authorizations', "authorizationsController@destroy")->name('api.authorizations.destroy');
    });

    $api->group([
        'middleware' => 'api.throttle',
        'limit' => config('api.rate_limits.access.limit'),
        'expires'=>config('api.rate_limits.access.expires')
        ], function ($api) {
        //游客可以访问的接口
        $api->get('categories',"CategoriesController@index")->name('api.categories.index');
        //需要token验证的接口
        $api->group(['middleware'=>'api.auth'],function ($api){
            $api->get('user',"UserController@me")->name('api.user.show');
            /*图片上传*/
            $api->post('images','ImagesController@store')->name('api.images.store');
            /*编辑用户接口*/
            $api->patch('user',"Usercontroller@update")->name('api.user.update');
        });
    });
});

$api->version('v2', function ($api) {
    $api->get('version', function () {
        return response('this is version v2');
    });
});

